package com.aboo.fastjson;


import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;

/**
 * @ClassName FastjsonMain
 * @Description
 * @Author louan
 * @Date 2021/3/25
 */
public class FastjsonMain {

    public static void main(String[] args) {
        MainVo main = new MainVo();
        main.setName("张三");
        main.setAge(27);
        main.setBase64Image("slaeflwqopiuropqjrla;sjfelajsldfja");

        JSONWriter.Feature[] feature = {
                // 使用单引号而不是双引号,默认为false
                JSONWriter.Feature.UseSingleQuotes,
                // 是否输出值为null的字段,默认为false
                JSONWriter.Feature.WriteMapNullValue,
                // Enum输出name()或者original,默认为false
                JSONWriter.Feature.WriteEnumUsingToString,
                // List字段如果为null,输出为[],而非null
                JSONWriter.Feature.WriteNullListAsEmpty,
                // 字符类型字段如果为null,输出为”“,而非null
                JSONWriter.Feature.WriteNullStringAsEmpty,
                // 数值字段如果为null,输出为0,而非null
                JSONWriter.Feature.WriteNullNumberAsZero,
                // Boolean字段如果为null,输出为false,而非null
                JSONWriter.Feature.WriteNullBooleanAsFalse,
                // 结果是否格式化,默认为false
                JSONWriter.Feature.PrettyFormat
        };

        String str = JSON.toJSONString(main, new FastjsonValueFilter(), JSONWriter.Feature.PrettyFormat);
        System.out.println(str);

        System.out.println(JSON.toJSONString(main, feature));
    }

}
